import { useAuth } from "../module";
/** 参数错误的状态码 */
const ERROR_PARAM_CODE = 10000;

const ERROR_PARAM_MSG = '参数校验失败！';
const apis = [
  {
    url: '/mock/login',
    method: 'post',
    response: (options: any) => {
      const { userName = undefined, passWord = undefined } = options.body;
      if(!userName && !passWord){
        return {
          code: ERROR_PARAM_CODE,
          message: ERROR_PARAM_MSG,
          data: null
        };
      }
      const userInfo = useAuth.find((item) => item.userName === userName && item.passWord ===  passWord);
      if(userInfo){
        return {
          code:200,
          message: '请求成功',
          data: {
            token: userInfo.token,
            role: userInfo.role,
            auth: userInfo.auth
          }
        };
      }else {
        return {
          code:400,
          message: '账户或密码输入错误',
          data: null
        };
      }

    }
  }
];
export default  apis;
